package cn.silver.module.system.enums;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.core.utils.StreamUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum DeptTypeEnums {
    /**
     *
     */
    COMPANY_GROUP("00", "集团", "company", "00", UserTypeEnums.GROUP_USER.getCode(), Boolean.TRUE),
    COMPANY_SIMAPLE("01", "投资公司", "company", "01", UserTypeEnums.COMPANY_USER.getCode(), Boolean.TRUE),
    GROUP_DEPT("10", "集团部门", "dept", "10", UserTypeEnums.GROUP_USER.getCode(), Boolean.TRUE),
    GROUP_NODE("11", "集团总部根节点", "node", "10", UserTypeEnums.GROUP_USER.getCode(), Boolean.TRUE),
    GROUP_TEAM("12", "集团项目组", "team", "12", UserTypeEnums.GROUP_USER.getCode(), Boolean.TRUE),
    COMPANY_NODE("20", "投企根节点", "node", "01", UserTypeEnums.COMPANY_USER.getCode(), Boolean.TRUE),
    COMPANY_DEPT("21", "投企部门", "dept", "21", UserTypeEnums.COMPANY_USER.getCode(), Boolean.TRUE),
    COMPANY_TEAM("22", "投企项目组", "team", "22", UserTypeEnums.COMPANY_USER.getCode(), Boolean.TRUE),
    EXTERNAL_USER("30", "外部用户组", "external", "99", UserTypeEnums.EXTERNAL_USER.getCode(), Boolean.FALSE),
    SUPPLIER_USER("31", "供应商用户组", "external", "99", UserTypeEnums.EXTERNAL_USER.getCode(), Boolean.FALSE),
    OTHER_USER("99", "其他", "other", "99", UserTypeEnums.OTHER_USER.getCode(), Boolean.TRUE),
    ;
    private final String code;
    private final String name;
    private final String group;
    private final String child;
    private final String identity;
    private final Boolean built;

    public static List<DictModel> getModels() {
        return StreamUtils.toList(Arrays.asList(values()), item -> new DictModel(item.name, item.code));
    }

    public static String getIdentity(String code) {
        return Stream.of(values()).filter(item -> item.getCode().equalsIgnoreCase(code)).map(DeptTypeEnums::getIdentity)
                .findFirst().orElse(DeptTypeEnums.OTHER_USER.getCode());
    }

    public static List<String> getInnerCode() {
        return Stream.of(values()).filter(DeptTypeEnums::getBuilt).map(DeptTypeEnums::getCode).collect(Collectors.toList());
    }

    public static String getChild(String code) {
        return Stream.of(values()).filter(item -> item.getCode().equalsIgnoreCase(code)).map(DeptTypeEnums::getChild)
                .findFirst().orElse(DeptTypeEnums.OTHER_USER.getCode());
    }
}
